import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";
import utils from "../../../src/utils/utils";
import contextPath from "../../context-path";
const Random = Mock.Random;

export default [
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/role.listing",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      const total = 112;
      let cnt = options.body.rows;
      if (options.body.rows * options.body.page > total) {
        cnt = total - options.body.rows * (options.body.page - 1);
      }
      for (let i = 0; i < cnt; i++) {
        const template = {
          roleId: Random.guid(),
          orderIndex: Random.increment(5),
          category: Mock.mock({
            "array|1": ["APP", "SYS"],
          }).array,
          roleName: Random.string("upper", 5),
          roleCode: Random.natural(60, 1000),
          description: Random.cparagraph(2),
        };
        rows.push(template);
      }

      return {
        code: 200,
        total: total,
        rows: rows,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/role.all",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      for (let i = 0; i < 115; i++) {
        const template = {
          roleId: Random.guid(),
          orderIndex: Random.increment(5),
          category: Mock.mock({
            "array|1": ["APP", "SYS"],
          }).array,
          roleName: Random.string("upper", 5),
          roleCode: Random.natural(60, 1000),
          description: Random.cparagraph(2),
        };
        rows.push(template);
      }

      return {
        code: 200,
        message: "",
        data: rows,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/role.get",
    method: "post",
    response: (options) => {
      const template = {
        roleId: Random.guid(),
        orderIndex: Random.increment(5),
        category: Mock.mock({
          "array|1": ["APP", "SYS"],
        }).array,
        roleName: Random.string("upper", 5),
        roleCode: Random.natural(60, 1000),
        description: Random.cparagraph(2),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/role.update",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/role.delete",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/role.resource.checked",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: [
          Random.guid(),
          Random.guid(),
          Random.guid(),
          Random.guid(),
          Random.guid(),
        ],
      };
    },
  },
] as MockMethod[];
